$("#province").on("change",function () {
    var city = $("#province").val();
    $("#area").html("");
    var html = " <option value=''>全部</option>";
    $("#area").append(html);
    getCity(city);
})
$("#city").on("change",function () {
    var city = $("#city").val();
    getArea(city);
})
function getCity(city){
    $.ajax({
        url: '/user/city',
        data: {city: city},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#city").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#city").append(html);
        }
    })
}

function getArea(area){
    $.ajax({
        url: '/user/area',
        data: {area: area},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#area").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#area").append(html);
        }
    })
}
$(document).ready(function(){
    ajaxList();
});
$(".search").click(function () {
    var data = $("#searchform").serialize();
    var start = $('.start_time').val();
    var end = $('.end_time').val();
    if(start==''||end==''){
        dshow('时间不能为空');
        return false
    }
    if(start > end){
        dshow('结束时间必须大于开始时间');
        return false
    }
    ajaxList(data);
});

function ajaxList(data) {
    $.ajax({
        url: '/user/echartsColumn',
        data: data,
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            columnPie(data.time,data.value);
            $(".stay").html(data.register);
            $(".complete").html(data.Authentication);
            $(".cancel").html(data.diff+'%');
        }
    })
}
function columnPie(dataX,dataY) {
    var myChart = echarts.init(document.getElementById('main'));
    option = {
        // title: {
        //     text: '新增注册用户',
        //     x: 'center'
        // },
        legend: {
            data:['新增注册用户'],
            top:30,
            textStyle: {
                fontSize: 16,
                fontWeight: 'bolder',
            }// 主标题文字颜色
        },
        dataZoom: [
            {
                show: true,
            },
            {
                type: 'inside',
            },
            {
                show: true,
                yAxisIndex: 0,
                filterMode: 'empty',
                width: 30,
                height: '80%',
                showDataShadow: false,
                left: '93%'
            }
        ],
        xAxis: {
            type: 'category',
            data: dataX
        },
        yAxis: {
            type: 'value'
        },
        series: [{
            data: dataY,
            type: 'line',
            name:'新增注册用户',
            itemStyle:{
                normal:{
                    color:'#70ad47',
                    // label:{
                    //     show:true,
                    //     position:'top'
                    //
                    // }
                }
            }
        }]
    };
    myChart.setOption(option);
}

